package com.quirqy.service;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.View;


import com.quirqy.model.Person;
import com.quirqy.persistence.EMF;
import javax.persistence.EntityManager; 

@Controller
public class RestPostService 
{

	@RequestMapping( value = "people",method = RequestMethod.POST )
	@ResponseStatus( HttpStatus.CREATED )
	@ResponseBody	
	public final Person add( @RequestBody final Person p )
	{
		EntityManager em = EMF.get().createEntityManager();
		em.getTransaction().begin();
		em.persist(p);
	    em.flush();
	    em.refresh(p);
		em.getTransaction().commit();
		em.close();
		return p;
	}
}
